%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "y.tab.h"
#include "symboles.h"


struct variable*
chercher(char* name,struct variable* v){
  while((v!=NULL)&&(strcmp(v->nom_var,name)!=0)){
    v=v->suivant;
    chercher(name,v);
  }
  return v;
}
 
 struct variable* t=NULL;
 FILE* f;
  %}
%token AND OR CLASS IF THEN ELSE END WHILE DO DEF LEQ GEQ 
%token FOR TO RETURN IN NEQ
%token <n> INT
%token <s> STRING
%token <d> FLOAT
%token <s> ID
%left '*' 
%left '/'
%left '+' '-'
%left '<' '>' LEQ GEQ EQ
%left AND OR
%type <va> primary lhs multiplicative_expr additive_expr comp_expr expr exprs
%union{
  int n;
  char* s;
  double d;
  struct variable* va;
 }
%%
program		:  topstmts opt_terms
;
topstmts        :      
| topstmt
| topstmts terms topstmt
;
topstmt	        : CLASS ID term stmts opt_terms END 
| CLASS ID '<' ID term stmts opt_terms END
| stmt
;

stmts	        : /* none */
| stmt
| stmts terms stmt
;

stmt		: IF expr THEN stmts opt_terms END  
| IF expr THEN stmts terms ELSE stmts terms END 
| FOR ID IN expr TO expr term stmts terms END 
| WHILE expr DO term stmts terms END 
| lhs '=' expr {if($3->tvar->ntype==3){fprintf(f,"%%%d = load i32* %%ptr%d \n",$1->numvar,$3->numvar);}else if($3->tvar->ntype==2){fprintf(f,"%%%d = load float* %%ptr%d \n",$1->numvar,$3->numvar);} else  exit(EXIT_FAILURE);}
| RETURN expr {printf("ret\n");struct variable* w=t;struct variable* v=chercher($2->nom_var,w);if(v!=NULL){fprintf(f,"ret i32t %%%d\n",v->numvar);}else if(v!=NULL){fprintf(f,"ret float %%%d\n",v->numvar);} else exit(EXIT_FAILURE); printf("ret fin\n");}
| DEF ID opt_params term stmts terms END
; 

opt_params      : /* none */
| '(' ')'       
| '(' params ')'
;
params          : ID ',' params    
| ID 
; 
lhs             : ID {printf("id\n");struct variable* w=t;struct variable* v=chercher($1,w);if(v==NULL){struct type ty; ty.ntype=6;ty.class_fcts=NULL;ty.fct_params=NULL;$$=ajouter_var(&t,&ty,$1);cmpt_val++;}else{$$=v;}}
| ID '.' primary   {struct variable* w=t;struct variable* v=chercher($1,w);if(v==NULL||(v->tvar->ntype!=CLAS)){exit(EXIT_FAILURE);}else{$$=$3;}}
| ID '(' exprs ')' {struct variable* w=t;struct variable* v=chercher($1,w);if(v==NULL||(v->tvar->ntype!=FCT)){exit(EXIT_FAILURE);}else{/*je sais pas*/}}
;
exprs        : exprs ',' expr  //and?
| expr {$$=$1;}
;

//Réprésentation temporaire 1 pour string, 2 pour float, 3 pour int,4 pour bool , mpt_val = compteur global pour le numvar, f descripteur de fichier ou on écrit le code assembleur LLVM

primary         : lhs    {printf("lhs\n");$$=$1;}
| STRING {struct type ty; ty.ntype=1;ty.valst=$1;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);}
| FLOAT  {printf("float\n");struct type ty; ty.ntype=2;ty.vald=$1;ty.class_fcts=NULL;ty.fct_params=NULL;printf("float type\n");char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);printf("float name\n");$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fadd float %f,%d\n",$$->numvar,$1,0);}
| INT    {printf("int\n");struct type ty; ty.ntype=3;ty.vali=$1;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = add i32 %d,%d\n",$$->numvar,$1,0);}
| '(' expr ')' {$$=$2;}
;
expr            : expr AND comp_expr {if($1->tvar->ntype==4 && $3->tvar->ntype==4){$$->tvar->ntype=4; if ($1->tvar->valb==true && $3->tvar->valb==true){$$->tvar->valb=true;} else $$->tvar->valb=false;}}
| expr OR comp_expr {if($1->tvar->ntype==4 && $3->tvar->ntype==4){$$->tvar->ntype=4; if ($1->tvar->valb==true || $3->tvar->valb==true){$$->tvar->valb=true;} else $$->tvar->valb=false;}}
| comp_expr {$$=$1;}
;
comp_expr       : additive_expr '<' additive_expr {printf("<\n");if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali<$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp slt i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald<$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp olt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali<$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp olt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald<$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp olt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr '>' additive_expr {if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali>$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp sgt i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald>$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ogt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali>$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ogt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald>$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ogt float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr LEQ additive_expr {if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali<=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp use i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald<=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ole float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali<=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ole float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald<=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp ole float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr GEQ additive_expr {if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali>=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp sge i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald>=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oge float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali>=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oge float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald>=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oge float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr EQ additive_expr  {if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali==$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp eq i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald==$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oeq float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali==$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oeq float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald==$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp oeq float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr NEQ additive_expr {if(($1->tvar->ntype==3)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali!=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = icmp ne i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==2)&&($3->tvar->ntype==3)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald!=$3->tvar->vali);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp one float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if(($1->tvar->ntype==3)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vali!=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp one float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}  else if(($1->tvar->ntype==2)&&($3->tvar->ntype==2)){struct type ty; ty.ntype=4;ty.valb=($1->tvar->vald!=$3->tvar->vald);ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fcmp one float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| additive_expr {$$=$1;} 
;

additive_expr   : multiplicative_expr {printf("add mult\n");$$=$1;}
| additive_expr '+' multiplicative_expr {printf("add\n");if($1->tvar->ntype==2 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald+$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fadd float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==2 && $3->tvar->ntype==3){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald+$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fadd float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vali+$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fadd float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==3){struct type ty; ty.ntype=3;ty.vali=$1->tvar->vali+$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = add i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else exit(EXIT_FAILURE);}
| additive_expr '-' multiplicative_expr {printf("sub\n");if($1->tvar->ntype==2 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald-$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fsub float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==2 && $3->tvar->ntype==3){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald-$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fsub float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vali-$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fsub float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==3){struct type ty; ty.ntype=3;ty.vali=$1->tvar->vali-$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = sub i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else exit(EXIT_FAILURE);}
;
multiplicative_expr : multiplicative_expr '*' primary {printf("mult\n");if($1->tvar->ntype==2 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald*$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fmul float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==2 && $3->tvar->ntype==3){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald*$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fmul float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vali*$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fmul float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==3){printf("mult en cours\n");struct type ty; ty.ntype=3;ty.vali=$1->tvar->vali*$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = mul i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);printf("mult fin\n");}
| multiplicative_expr '/' primary {printf("div\n");if($1->tvar->ntype==2 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald/$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fdiv float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==2 && $3->tvar->ntype==3){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vald/$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fdiv float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==2){struct type ty; ty.ntype=2;ty.vald=$1->tvar->vali/$3->tvar->vald;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = fdiv float %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);} else if($1->tvar->ntype==3 && $3->tvar->ntype==3){struct type ty; ty.ntype=2;ty.vali=$1->tvar->vali/$3->tvar->vali;ty.class_fcts=NULL;ty.fct_params=NULL;char num[100];sprintf(num,"%d",cmpt_val);char name[256];strcat(name,"name_v");strcat(name,num);$$=ajouter_var(&t,&ty,name);fprintf(f,"%%%d = div i32 %%%d,%%%d\n",$$->numvar,$1->numvar,$3->numvar);}else exit(EXIT_FAILURE);}
| primary {printf("mult primary\n");$$=$1;}
;
opt_terms	: /* none */ 
| terms 
;

terms		: terms ';'     
| terms '\n'    
| ';'  
| '\n' 
;
term            : ';'  
| '\n' 
;
%%
int main() {

 
  f=fopen("test.ll","a+");
  yyparse();
  //fclose(f);
  //liberer_table(t);
  return EXIT_SUCCESS;
}
